<?php
if(!defined('IN_WOGU')) {
    exit('Access Denied');
}

Loader::loadClass('Model');

class CatModel extends Model
{
    protected $_table = 'cat';

    public function addCat($data) {
        return $this->insert($data, true);
    }
    
    public function getCat($where) {
        return $this->getOne($where);
    }
    
    public function deleteCat($id) {
        $this->delete(array('id' => $id));

        $cats = $this->getCats(array('parent_id' => $id));
        foreach($cats as $cat) {
            $this->deleteCat($cat['id']);
        }
    }
    
    public function updateCat($data, $where) {
        return $this->update($data, $where);
    }
    
    public function listCats($where, $page = 1, $perpage = 30, $order = 'id ASC') {
        Loader::loadClass('Page');
        return $this->listInfo($where, $page, $perpage, $order, '');
    }
    
    public function getCats($where = '', $data = '*') {
        return $this->select($where, $data, '', 'id ASC', '', 'id');
    }
}